﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectWebNhac.BUS;
using System.Data;


namespace ProjectWebNhac.GUI.User
{
    public partial class Video : System.Web.UI.Page
    {
        TheLoaiBus tlbus = new TheLoaiBus();
        VideoBus vdBus = new VideoBus();
        int maTheLoai = -1;
        int Pages = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
              if (Request["MaTheLoai"]!=null)
            {
                maTheLoai = Convert.ToInt16(Request["MaTheLoai"]);
            }
            if (Request["page"] != null)
            {
                Pages = Convert.ToInt16(Request["page"]);
            }
            if (!Page.IsPostBack)
            {
                loadDanhSachTheLoai();
                LoadDanhSachVideo();
            }
        }

        private void loadDanhSachTheLoai()
        {
            reTheLoai.DataSource = tlbus.LayTheLoaiNhac();
            reTheLoai.DataBind();
        }

        private void LoadDanhSachVideo()
        {
            DataSet ds = vdBus.LayDanhSachVideoPT(Pages, 20, 10, maTheLoai);

            DataTable dtbData = ds.Tables[0];

            if (dtbData.Rows.Count > 0)
            {
                DataTable dtbPhanTrang= null;
                if (ds.Tables[1]!=null)
                {
                    dtbPhanTrang = ds.Tables[1];
                }
                 
                dtbData.Columns.Add("RowIndex", typeof(System.Int32));
                int i = 1;
                foreach (DataRow dr in dtbData.Rows)
                {
                    dr["RowIndex"] = i;
                    i++;
                }
                reVideo.DataSource = dtbData;
                reVideo.DataBind();
                liPage.Text = dtbPhanTrang.Rows[0][0].ToString();
            }
        }
    }
}